MovingPandas Minimum Viable Example¶

Binder

MovingPandas provides a trajectory datatype based on GeoPandas. The project home is at https://github.com/movingpandas/movingpandas

The documentation is available at https://movingpandas.readthedocs.io/en/main/

In [1]:
import warnings
warnings.filterwarnings('ignore')
In [2]:
import pandas as pd
import geopandas as gpd
import movingpandas as mpd
from hvplot import pandas
from datetime import datetime, timedelta

Loading trajectory data from a GeoPackage¶

The MovingPandas repository contains a demo GeoPackage file that can be loaded as follows:

In [3]:
gdf = gpd.read_file('../data/geolife_small.gpkg')
gdf.plot(figsize=(9,5))
Out[3]:
<AxesSubplot: >
In [4]:
gdf.hvplot(geo=True).opts(active_tools=['pan', 'wheel_zoom'])
Out[4]:

After reading the trajectory point data from file, we want to construct the trajectories.

Creating a TrajectoryCollection¶

In [5]:
traj_collection = mpd.TrajectoryCollection(gdf, 'trajectory_id', t='t')
traj_collection
Out[5]:
TrajectoryCollection with 5 trajectories
In [6]:
traj_collection.plot(column='trajectory_id', legend=True, figsize=(9,5))
Out[6]:
<AxesSubplot: >

Exploring movement speed¶

In [7]:
traj_collection.plot(column='speed', linewidth=5, capstyle='round', legend=True, vmax=20, figsize=(9,5))
Out[7]:
<AxesSubplot: >

Detecting stops¶

In [8]:
detector = mpd.TrajectoryStopDetector(traj_collection)
stop_points = detector.get_stop_points(min_duration=timedelta(seconds=120), max_diameter=100)
In [9]:
ax = traj_collection.plot(figsize=(9,5))
stop_points.plot(ax=ax, color='red', markersize=100)
Out[9]:
<AxesSubplot: >
In [10]:
( traj_collection.hvplot(line_width=7, tiles=None, frame_width=400, frame_height=400) * 
 stop_points.hvplot(geo=True, color='black', size=100) )
Out[10]:
In [ ]: